from po_model.Unit1.page import page
import unittest
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By


class case(unittest.TestCase):
    def setUp(self) -> None:
        self.driver= webdriver.Edge()
        self.driver.maximize_window()

    def tearDown(self) -> None:
        sleep(5)
        self.driver.quit()

    def test_zhixng(self):
        po= page(self.driver)
        po.luoji_A3mall()

    def test_zhixing_01(self):
        po= page(self.driver)
        po.get_url("http://10.59.9.12:7001/")
        po.denglu_shouye()
        sleep(1)
        po.username_text()
        sleep(1)
        po.password_text()
        sleep(6)
        po.denglu_btn()
        sleep(5)
        # 数据库用户信息断言
        denglu = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').text

        print(denglu)
        denglu1 = denglu.replace("欢迎回来，", "")
        print(denglu1)
        # 查询数据库名称
        username = po.sql.select("select username from mall_users where id='330'")
        print(username[0][0])
        # 登录用户信息数据库断言
        try:
            assert denglu1, username[0][0]
            print("用户名断言成功")
        except Exception as e:
            print(f"断言失败:{e}")
        sleep(1)
        # 节点断言登录时的余额
        po.login_money()

        sleep(1)
        po.shouye_click()
        sleep(1)
        po.select_sendkeys()
        sleep(1)
        po.select_btn()
        sleep(1)
        po.sp_xiangqing()
        sleep(2)
        # 节点断言商品价格
        po.sp_price()
        sleep(1)
        po.buy()
        sleep(1)
        po.address()
        sleep(1)
        # 滑动
        po.hua()
        sleep(1)
        po.next()
        sleep(1)
        po.look()
        sleep(1)
        po.two_info()
        # 支付成功后的余额
        po.after_yue()
        sleep(1)
        po.wode_dd()
        sleep(1)
        po.dd_xiang()


if __name__ == '__main__':
    unittest.main()
